/**
 * 
 */
package cn.miao.learn.ssh.interceptor;

import java.util.Map;

import org.apache.log4j.Logger;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

/**
 * @author nealmiao
 *
 */
public class LoginInterceptor extends AbstractInterceptor {

	private static final long serialVersionUID = -1129412004481368538L;
	Logger logger = Logger.getLogger(getClass());
	String USER_KEY = "USERSESESSION";

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		Map<String, Object> session = invocation.getInvocationContext()
				.getSession();
		session.put(USER_KEY, "YES");
		if (session.containsKey(USER_KEY)) {
			logger.info("\t用户已经登录，action继续往下走");
			return invocation.invoke();
		} else {
			logger.info("\t用户登录信息过期，回到loginAcion");
			return Action.LOGIN;
		}
	}

}
